const log = require('log-mini')
const crypto = require('./crypto')

log.config({
  debug: process.env.NODE_ENV !== 'production',
  absolute: false
})

function sleep(t) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve()
    }, t || 15)
  })
}

function makeSign () {
  var key = crypto.randomBytes()
  var privateKey = process.env.PRIVATE_KEY || '123456'
  var sign = crypto.hash(key + privateKey, 'hex', 'md5')
  return {
    key,
    sign
  }
}


global.log = log
global.makeSign = makeSign
global.sleep = sleep
